package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark48Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark48 extends BaseMark {

    LayoutWatermark48Binding binding;

    public Mark48(@NonNull Context context) {
        super(context);
    }

    public Mark48(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark48(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark48Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark48Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
        if (type == 0) {
            hideView(binding.binding3, binding.binding5, binding.binding9, binding.binding10, binding.binding12);
        }
    }

    @Override
    public void update() {

        setText(binding.binding1, "time48", binding.binding1);
        setTime(binding.binding7, new SimpleDateFormat("yyyy.MM.dd"));
        setWeek(binding.binding8);
        setTime(binding.binding1, new SimpleDateFormat("HH:mm"));
        setText(binding.binding2, "didian48", binding.binding2);
        setText(binding.binding4, "no48", binding.binding3);
        setText(binding.binding5, "jingwei48", binding.binding5);
        setText(binding.binding9, "weather48", binding.binding9);
        setText(binding.binding11, "speed48", binding.binding10);

        setText(binding.binding12, "title48", binding.binding12);

        setText(binding.binding14, "tip48", binding.binding13);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("time48", "时间", true));
        list.add(new EditItem("didian48", "地点"));
        list.add(new EditItem("no48", "编号"));
        list.add(new EditItem("jingwei48", "经纬度"));
        list.add(new EditItem("weather48", "天气"));
        list.add(new EditItem("speed48", "风速"));
        list.add(new EditItem("title48", "标题"));
        list.add(new EditItem("tip48", "提示"));


        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding7, new SimpleDateFormat("yyyy.MM.dd"));
            setWeek(binding.binding8);
            setTime(binding.binding1, new SimpleDateFormat("HH:mm"));
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isTime) {
            if (item.show) {
                showView(binding.binding1, binding.binding6);
            } else {
                hideView(binding.binding1, binding.binding6);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
